package io.wit.modules.sys.service.impl;

import io.wit.modules.sys.dao.EmployeeRoleMenuDao;
import io.wit.modules.sys.service.EmployeeRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工角色与菜单对应关系
*/
@Service("employeeRoleMenuService")
public class EmployeeRoleMenuServiceImpl implements EmployeeRoleMenuService{

    @Autowired
	private EmployeeRoleMenuDao employeeRoleMenuDao;

	@Override
	@Transactional
	public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
		//先删除角色与菜单关系
		employeeRoleMenuDao.delete(roleId);
		if(menuIdList.size() == 0){
			return ;
		}
		//保存员工角色与菜单关系
		Map<String, Object> map = new HashMap<>();
		map.put("roleId", roleId);
		map.put("menuIdList", menuIdList);
		employeeRoleMenuDao.save(map);
	}

	@Override
	public List<Long> queryMenuIdList(final Long roleId) {
		return employeeRoleMenuDao.queryMenuIdList(roleId);
	}
}